package com.sskj.fabi.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.R;
import com.sskj.fabi.bean.FBPrice;
import com.sskj.fabi.bean.PayWayBean;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.activity.FabiPublishActivity;
import com.sskj.lib.http.JsonCallBack;

import java.util.ArrayList;
import java.util.List;

public class FabiPublishPresenter extends BasePresenter<FabiPublishActivity> {
    /**
     * 获取发布价格
     */
    public void getFbPrice() {
        httpService.getFbPrice()
                .tag(this)
                .execute(new JsonCallBack<HttpData<FBPrice>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<FBPrice>> response) {
                        mView.setData(response.body().getData());
                    }

                    @Override
                    public void onError(Response<HttpData<FBPrice>> response) {
                        super.onError(response);
                    }
                });
    }

    /**
     * 获取支付方式
     */
    public void requsetPayWayList() {
        httpService.getPayList()
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<PayWayBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<List<PayWayBean>>> response) {
                        mView.onPayWaySuccess(response.body());
                    }

                    @Override
                    public void onError(Response<HttpData<List<PayWayBean>>> response) {
                        super.onError(response);
                    }
                });
    }

    /**
     * 发布订单
     */

    public void requsetPublish(String trans_num, String min_price, String max_price,
                               String type, int pay_wx, int pay_alipay, int pay_backcard, int paypal, String notes, String pay_pwd) {
        httpService.createFabiOrder(trans_num, min_price, max_price, type, pay_wx, pay_alipay, pay_backcard, paypal, notes, pay_pwd)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.updateUi();
                        }
                    }
                });

    }
}
